home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / SymbolTableEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  5.8 KB  |  180 lines  |  [TEXT/KAHL]

  1. /* SymbolTableEntry.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "SymbolTableEntry.h"
  31. #include "CRC32.h"
  32. #include "TrashTracker.h"
  33. #include "Memory.h"
  34. #include "SymbolList.h"
  35.  
  36.  
  37. struct SymbolRec
  38.     {
  39.         SymbolType                Type;
  40.         char*                            SymbolName;
  41.         unsigned long            HashValue;
  42.         DataTypes                    ObjectDataType;
  43.         SymbolListRec*        FunctionArgList;
  44.         long                            VariableStackAddress;
  45.     };
  46.  
  47.  
  48. /* create a new symbol table entry for a variable */
  49. SymbolRec*                NewSymbol(struct TrashTrackRec* Trash, char* String, long StringLength)
  50.     {
  51.         SymbolRec*            Symbol;
  52.  
  53.         Symbol = (SymbolRec*)AllocTrackedBlock(sizeof(SymbolRec),Trash);
  54.         if (Symbol == NIL)
  55.             {
  56.                 return NIL;
  57.             }
  58.         SetTag(Symbol,"SymbolRec: NewVariableSymbol");
  59.  
  60.         Symbol->SymbolName = AllocTrackedBlock(StringLength,Trash);
  61.         if (Symbol->SymbolName == NIL)
  62.             {
  63.                 return NIL;
  64.             }
  65.         SetTag(Symbol->SymbolName,"NewVariableSymbol:  name string");
  66.  
  67.         EXECUTE(Symbol->VariableStackAddress = -1;)
  68.  
  69.         Symbol->Type = eSymbolUndefined;
  70.         CopyData(String,Symbol->SymbolName,StringLength);
  71.         Symbol->HashValue = CalculateCRC32(Symbol->SymbolName,StringLength);
  72.         return Symbol;
  73.     }
  74.  
  75.  
  76. /* find out what the symbol is a symbol of */
  77. SymbolType                WhatIsThisSymbol(SymbolRec* Symbol)
  78.     {
  79.         CheckPtrExistence(Symbol);
  80.         return Symbol->Type;
  81.     }
  82.  
  83.  
  84. /* get the hash value for the string */
  85. unsigned long            GetSymbolHashValue(SymbolRec* Symbol)
  86.     {
  87.         CheckPtrExistence(Symbol);
  88.         return Symbol->HashValue;
  89.     }
  90.  
  91.  
  92. /* get a pointer to the actual string name of the variable */
  93. char*                            GetSymbolName(SymbolRec* Symbol)
  94.     {
  95.         CheckPtrExistence(Symbol);
  96.         return Symbol->SymbolName;
  97.     }
  98.  
  99.  
  100. /* make symbol into a variable symbol */
  101. void                            SymbolBecomeVariable(SymbolRec* Symbol, DataTypes VarType)
  102.     {
  103.         CheckPtrExistence(Symbol);
  104.         ERROR(Symbol->Type != eSymbolUndefined,PRERR(ForceAbort,
  105.             "GetSymbolVariableDataType:  symbol has already been defined"));
  106.         Symbol->Type = eSymbolVariable;
  107.         Symbol->ObjectDataType = VarType;
  108.     }
  109.  
  110.  
  111. /* make variable know where on the stack it lives */
  112. void                            SetSymbolVariableStackLocation(SymbolRec* Symbol, long StackLoc)
  113.     {
  114.         CheckPtrExistence(Symbol);
  115.         ERROR(StackLoc < 0,PRERR(ForceAbort,"SetSymbolVariableStackLocation:  negative index"));
  116.         ERROR(Symbol->VariableStackAddress >= 0,PRERR(ForceAbort,
  117.             "SetSymbolVariableStackLocation:  location has already been set"));
  118.         Symbol->VariableStackAddress = StackLoc;
  119.     }
  120.  
  121.  
  122. /* find out where on the stack a variable lives. */
  123. long                            GetSymbolVariableStackLocation(SymbolRec* Symbol)
  124.     {
  125.         CheckPtrExistence(Symbol);
  126.         ERROR(Symbol->VariableStackAddress < 0,PRERR(ForceAbort,
  127.             "SetSymbolVariableStackLocation:  location has already been set"));
  128.         return Symbol->VariableStackAddress;
  129.     }
  130.  
  131.  
  132. /* get the object type for the variable */
  133. DataTypes                    GetSymbolVariableDataType(SymbolRec* Symbol)
  134.     {
  135.         CheckPtrExistence(Symbol);
  136.         ERROR(Symbol->Type != eSymbolVariable,PRERR(ForceAbort,
  137.             "GetSymbolVariableDataType:  not a variable"));
  138.         return Symbol->ObjectDataType;
  139.     }
  140.  
  141.  
  142. /* make symbol into a function symbol */
  143. void                            SymbolBecomeFunction(SymbolRec* Symbol, struct SymbolListRec* ArgList,
  144.                                         DataTypes ReturnType)
  145.     {
  146.         CheckPtrExistence(Symbol);
  147.         ERROR(Symbol->Type != eSymbolUndefined,PRERR(ForceAbort,
  148.             "GetSymbolVariableDataType:  already defined"));
  149.         Symbol->Type = eSymbolFunction;
  150.         Symbol->ObjectDataType = ReturnType;
  151.         Symbol->FunctionArgList = ArgList;
  152.     }
  153.  
  154.  
  155. /* get the return type for the function */
  156. DataTypes                    GetSymbolFunctionReturnType(SymbolRec* Symbol)
  157.     {
  158.         CheckPtrExistence(Symbol);
  159.         ERROR(Symbol->Type != eSymbolFunction,PRERR(ForceAbort,
  160.             "GetSymbolVariableDataType:  not a function"));
  161.         return Symbol->ObjectDataType;
  162.     }
  163.  
  164.  
  165. /* get the list of symbol table entries from a function call argument list */
  166. struct SymbolListRec*    GetSymbolFunctionArgList(SymbolRec* Symbol)
  167.     {
  168.         CheckPtrExistence(Symbol);
  169.         ERROR(Symbol->Type != eSymbolFunction,PRERR(ForceAbort,
  170.             "GetSymbolFunctionArgList:  symbol table entry is not a function"));
  171.         return Symbol->FunctionArgList;
  172.     }
  173.  
  174.  
  175. /* perform a hash on a name */
  176. unsigned long            UseSymbolTableHash(char* String, long Length)
  177.     {
  178.         return CalculateCRC32(String,Length);
  179.     }
  180.